package homework.test8;

public class MyThread8 implements Runnable{
    private int ticket = 100;
    private Object obj = new Object();
    @Override
    public void run() {
        while (true){
            synchronized (obj) {
                if(ticket <= 0){
                    break;
                }else {
                    ticket--;
                    System.out.println(Thread.currentThread().getName()+"在卖票，还剩"+ticket+"张票");
                }
            }
        }
    }
}
